package com.ruoyi.web.controller.uav;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.uav.domain.UavTaskRecord;
import com.ruoyi.uav.service.IUavTaskRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 任务记录Controller
 *
 * @author ruoyi
 * @date 2024-06-07
 */
@RestController
@RequestMapping("/uav/record")
@Api(value = "任务记录控制层", tags = "任务记录控制层")
public class UavTaskRecordController extends BaseController {
    @Resource
    private IUavTaskRecordService uavTaskRecordService;

    /**
     * 查询任务记录列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询任务记录列表", notes = "传入uavTaskRecord")
    public TableDataInfo list(UavTaskRecord uavTaskRecord) {
        startPage();
        List<UavTaskRecord> list = uavTaskRecordService.selectUavTaskRecordList(uavTaskRecord);
        return getDataTable(list);
    }

    /**
     * 导出任务记录列表
     */
    @PreAuthorize("@ss.hasPermi('uav:record:export')")
    @Log(title = "任务记录", businessType = BusinessType.EXPORT)
    @RepeatSubmit(interval = 2000, message = "请求过于频繁")
    @GetMapping("/export")
    @ApiOperation(value = "导出任务记录列表", notes = "传入uavTaskRecord")
    public AjaxResult export(UavTaskRecord uavTaskRecord) {
        List<UavTaskRecord> list = uavTaskRecordService.selectUavTaskRecordList(uavTaskRecord);
        ExcelUtil<UavTaskRecord> util = new ExcelUtil<UavTaskRecord>(UavTaskRecord.class);
        return util.exportExcel(list, "任务记录数据");
    }

    /**
     * 获取任务记录详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取任务记录详细信息", notes = "传入id")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(uavTaskRecordService.getInfo(id));
    }

    /**
     * 新增任务记录
     */
    @Log(title = "任务记录", businessType = BusinessType.INSERT)
    @RepeatSubmit(interval = 2000, message = "请求过于频繁")
    @PostMapping
    @ApiOperation(value = "新增任务记录", notes = "传入uavTaskRecord")
    public AjaxResult add(@RequestBody UavTaskRecord uavTaskRecord) {
        uavTaskRecord.setUserId(SecurityUtils.getUserId());
        uavTaskRecordService.save(uavTaskRecord);
        return success(uavTaskRecord);
    }

    /**
     * 修改任务记录
     */
//    @Log(title = "任务记录", businessType = BusinessType.UPDATE)
//    @RepeatSubmit(interval = 2000, message = "请求过于频繁")
//    @PutMapping
//    @ApiOperation(value = "修改任务记录", notes = "传入uavTaskRecord")
//    public AjaxResult edit(@RequestBody UavTaskRecord uavTaskRecord) {
//        return success(uavTaskRecordService.updateById(uavTaskRecord));
//    }

    /**
     * 删除任务记录
     */
//    @Log(title = "任务记录", businessType = BusinessType.DELETE)
//    @RepeatSubmit(interval = 2000, message = "请求过于频繁")
//	@DeleteMapping("/{ids}")
//    @ApiOperation(value = "删除任务记录", notes = "传入ids")
//    public AjaxResult remove(@PathVariable Long[] ids) {
//        return success(uavTaskRecordService.removeBatchByIds(Arrays.asList(ids)));
//    }

    /**
     * 查询最新任务记录列表
     */
    @GetMapping("/listByCreateTime")
    @ApiOperation(value = "查询最新任务记录列表")
    public TableDataInfo list() {
        startPage();
        UavTaskRecord uavTaskRecord = new UavTaskRecord();
        uavTaskRecord.setSortField("create_time");
        uavTaskRecord.setSortOrder("desc");
        List<UavTaskRecord> list = uavTaskRecordService.selectUavTaskRecordList(uavTaskRecord);
        return getDataTable(list);
    }

    /**
     * 查询任务记录分数排行列表
     */
    @GetMapping("/listByScore")
    @ApiOperation(value = "查询任务记录分数排行列表")
    public TableDataInfo listByScore() {
        startPage();
        UavTaskRecord uavTaskRecord = new UavTaskRecord();
        uavTaskRecord.setSortField("score");
        uavTaskRecord.setSortOrder("desc");
        List<UavTaskRecord> list = uavTaskRecordService.selectUavTaskRecordList(uavTaskRecord);
        return getDataTable(list);
    }

    @GetMapping("/homeInfo")
    @ApiOperation(value = "查询首页信息列表")
    public AjaxResult homeList() {
        return success(uavTaskRecordService.selectUavHomeInfo());
    }
}
